package com.ruoyi.rsikManage.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.rsikManage.domain.BroadCast;
import com.ruoyi.rsikManage.domain.MonitorPoint;
import com.ruoyi.rsikManage.domain.vo.*;
import com.ruoyi.rsikManage.service.BroadcastService;
import com.ruoyi.rsikManage.service.MonitorPointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/rsikManage/broadcast")
public class BroadcastController extends BaseController {
    @Autowired
    BroadcastService broadcastService;
    @Autowired
    MonitorPointService monitorPointService;

    /**
     * 查询gis上的所有广播
     */
    @GetMapping("allGisBroadcasts")
    public TableDataInfo allGisBroadcasts(BroadCast broadcast) {
        startPage();
        List<GisBroadcastVo> res = broadcastService.selectAllGisBroadcasts(broadcast);
        return getDataTable(res);
    }
    /**
     * 查询gis上有坐标的广播
     */
    @GetMapping("gisBroadcastsHasCoordinates")
    public TableDataInfo gisBroadcastsHasCoordinates() {
        startPage();
        List<GisBroadcastVo> res = broadcastService.selectGisBroadcastsHasCoordinates();
        return getDataTable(res);
    }
    /**
     * 配置广播的Gis坐标
     */
    @PutMapping("updateGisBroadcastsCoordinates")
    private AjaxResult updateGisBroadcastsCoordinates(@Validated @RequestBody GisBroadcastVo gisBroadcastVo) {
        broadcastService.updateGisBroadcastsCoordinates(gisBroadcastVo);
        return AjaxResult.success();
    }
    /**
     * 3D：查询所有广播的3D坐标
     */
    @GetMapping("allBroadcasts3D")
    public TableDataInfo selectAllBroadcasts3D(GisBroadcasts3DVo gisBroadcasts3DVo) {
        startPage();
        List<GisBroadcasts3DVo> res = broadcastService.selectAllBroadcasts3D(gisBroadcasts3DVo);
        return getDataTable(res);
    }
    /**
     * 3D：查询有3D坐标的广播
     */
    @GetMapping("gisBroadcastsHas3DCoordinates")
    public TableDataInfo gisBroadcastsHas3DCoordinates() {
        startPage();
        List<GisBroadcasts3DVo> res = broadcastService.gisBroadcastsHas3DCoordinates();
        return getDataTable(res);
    }
    /**
     * 3D：配置广播的3D坐标
     */
    @PutMapping("updateGisBroadcasts3DCoordinates")
    private AjaxResult updateGisBroadcasts3DCoordinates(@Validated @RequestBody GisBroadcasts3DVo gisBroadcasts3DVo) {
        broadcastService.updateGisBroadcasts3DCoordinates(gisBroadcasts3DVo);
        return AjaxResult.success();
    }

    /**
     * 查询所有广播
     */
    //  算法文件查询
    @GetMapping("selectBroadcastList/v2")
    public AjaxResult selectBroadcastList () {
        List<BroadCast> res  = broadcastService.selectBroadcastList();
        return AjaxResult.success(res);
    }
    /**
     * 查询所有广播
     */
    //  算法文件查询
    @GetMapping("selectBroadcastList")
    public AjaxResult selectBroadcastListForUnitCodes ( BroadCast broadCast) {


        List<BroadCast> res  = broadcastService.selectBroadcastListForUnitCodes(broadCast);
        return AjaxResult.success(res);
    }

    /**
     * 查询所有监控点
     */
    @GetMapping("selectAllMonitors/v2")
    public List<MonitorPointVO> selectAllMonitors() {
        return  monitorPointService.selectAllMonitors();
    }

    /**
     * 查询所有监控点
     */
    @GetMapping("selectAllMonitors")
    public List<MonitorPointVO> selectAllMonitorsForUnitCodes(MonitorPoint monitorPoint) {
        return  monitorPointService.selectAllMonitorsForUnitCodes(monitorPoint);
    }


    /**
     * 查询广播对应的监控点
     */
    @GetMapping("selectBroadcastAndMonitorsAssociation")
    public AjaxResult selectBroadcastAndMonitorsAssociation(@RequestParam Integer broadcastId) {
        BroadcastAndMonitorsRelResp res = broadcastService.selectBroadcastAndMonitorsAssociation(broadcastId);
        return success(res);
    }

    /**
     * 查询监控点对应的广播
     */
    @GetMapping("selectMonitorAssociatedBroadcasts/v2")
    public AjaxResult selectMonitorAssociatedBroadcasts(@RequestParam String monitorId) {
        List<BroadCast> res = broadcastService.selectMonitorAssociatedBroadcasts(monitorId);
        return success(res);
    }

    /**
     * 查询监控点对应的广播
     */
    @GetMapping("selectMonitorAssociatedBroadcasts")
    public AjaxResult selectMonitorAssociatedBroadcastsForUnitCodes(@RequestParam String monitorId, Long unitCode) {
        List<BroadCast> res = broadcastService.selectMonitorAssociatedBroadcastsForUnitCodes(monitorId,unitCode);
        return success(res);
    }

    /**
     * 修改某广播关联的监控点
     */
    @PutMapping("modifyBroadcastAndMonitorsAssociation")
    public AjaxResult modifyBroadcastAndMonitorsAssociation(@Validated @RequestBody BroadcastAndMonitorsRelResq broadcastAndMonitorsRel) {
        broadcastService.modifyBroadcastAndMonitorsAssociation(broadcastAndMonitorsRel);
        return success();
    }

    /**
     *  查询广播对应的所有用电设备
     */
    @GetMapping("selectBroadcastAndEquipAssociation")
    public AjaxResult selectBroadcastAndEquipAssociation(@RequestParam Integer broadcastId) {
        BroadcastAndEquipsRelResp res = broadcastService.selectBroadcastAndEquipAssociation(broadcastId);
        return success(res);
    }

    /**
     * 查询用电设备对应的所有广播
     */
    @GetMapping("selectEquipAssociatedBroadcasts")
    public AjaxResult selectEquipAssociatedBroadcasts(@RequestParam String equipCode) {
        List<BroadCast> res = broadcastService.selectEquipAssociatedBroadcasts(equipCode);
        return success(res);
    }
    /**
     * 修改某广播关联的用电设备
     */
    @PutMapping("modifyBroadcastAndEquipsAssociation")
    public AjaxResult modifyBroadcastAndEquipsAssociation(@Validated @RequestBody BroadcastAndEquipsRelResq broadcastAndEquipsRel) {
        broadcastService.modifyBroadcastAndEquipsAssociation(broadcastAndEquipsRel);
        return success();
    }
    /**
     * 2024-05-01 新增
     */

    /**
     * 更新广播列表
     */
    @PutMapping("updateBroadCastList")
    public AjaxResult updateBroadCastList() {
         return  broadcastService.updateBroadCastListV2();
    }

    /**
     * 广播播报
     */
    @GetMapping("playBroadCast")
    public void playBroadCast() {
        broadcastService.playBroadCast();
    }
}
//
